// pages/GroupDetail/GroupDetail.js
var app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 首页轮播图
    imgUrls: [],
    indicatorDots: true,
    autoplay: true,
    interval: 3000,
    duration: 500,
    listData: [
      { "code": "1", "time": "2019-01-17", "type": "type1" },
      { "code": "2", "time": "2019-04-20", "type": "type2" },
    ],
    // 是否已经提交申请
    sub_status: 2,
    // 是否有群活动
    isHasActivity:1,
    jiarumodel:true,
    tuimodel:true,
    huodongList:[],
    dashiji:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that=this;
    var qundetail=wx.getStorageSync('qundetail');
    var data = {
      paraUrl: "group/find/group?groupId=" + qundetail,
      paraData: ''
    }
    app.getRequest(data, function (res) {
      if (res.data.result == 200) {
        var imgUrlsArr=[]
        for (var i = 0; i < res.data.body.imageUrls.length;i++){
          var imgUrls ={
            imgUrl: res.data.body.imageUrls[i],
            article_id: i+1
          }
          imgUrlsArr.push(imgUrls)
        }
        that.setData({
          listDetail: res.data.body,
          imgUrls: imgUrlsArr
        })
      } else {
        
      }
    })
    wx.setStorageSync('activorgroup', 1);
    var that = this;
    var data = {
      paraUrl: "task/page/group?groupId=" + qundetail + "&page=1&size=3",
      paraData: ''
    }
    app.getRequest(data, function (res) {
      if (res.data.result == 200) {
        that.setData({
          huodongList: res.data.body.content
        })
      } else {

      }
    })
    var data = {
      paraUrl: "chronicle/list/group?groupId=" + qundetail,
      paraData: ''
    }
    app.getRequest(data, function (res) {
      if (res.data.result == 200) {
        that.setData({
          dashiji: res.data.body.content
        })
      } else {

      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  // 弹出层
  modalinput: function () {
    var that = this;
    that.setData({
      jiarumodel: false
    })
  },
  // 关闭
  cancel:function(){
    var that=this;
    that.setData({
      jiarumodel: true,
      tuimodel: true
    })
  },
  // 确认
  confirm:function(){
    var that = this;
    var qundetail = wx.getStorageSync('qundetail');
    var data = {
      paraUrl: "group-member/join?groupId=" + qundetail,
      paraData: ''
    }
    app.postRequest(data, function (res) {
      if (res.data.result == 200) {
        wx.showToast({
          title: '加入成功',
          icon: 'success',
          duration: 2000
        })
        that.setData({
          jiarumodel: true
        })
        that.onShow();
      } else if (res.data.result == 60008){
        wx.showToast({
          title: '已加入过该群',
          icon: 'success',
          image: '/images/shibai.png',
          duration: 2000
        })
      }
    })
  },
  //确认退群
  confirmtuiqun:function(){
    var that=this;
    var qundetail = wx.getStorageSync('qundetail');
    var data = {
      paraUrl: "group-member/quit?groupId=" + qundetail,
      paraData: ''
    }
    app.postRequest(data, function (res) {
      if (res.data.result == 200) {
        wx.showToast({
          title: '退出成功',
          icon: 'success',
          duration: 2000
        })
        that.setData({
          tuimodel: true
        })
        that.onShow();
      } 
    })
  },
  //确认弹出框
  tuimodel:function(){
    var that = this;
    that.setData({
      tuimodel: false
    })
  },
  //进入群组
  jinru:function(){
    wx.navigateTo({
      url: '../GroupDetailList/GroupDetailList'
    })
  },
  toActivityDetail: function (e) {
    wx.setStorageSync("taskId", e.currentTarget.id)
    wx.navigateTo({
      url: '/pages/ActivityDetail/ActivityDetail'
    })
  }
})